<template>
  <view class="container">
    <view class="wx_title">"中心荟"党员群众微心愿</view>
    <view class="page-body">
      <form @submit="formSubmit">
        <view class="page-section">
          <view class="weui-cells__title">姓名<text class="red">　*</text></view>
          <view class="weui-cells weui-cells_after-title">
            <view class="weui-cell weui-cell_input">
              <input name="user_name" class="weui-input" placeholder="　请输入姓名"/>
            </view>
          </view>
        </view>        

        <view class="page-section">
          <view class="weui-cells__title">联系方式<text class="red">　*</text></view>
          <view class="weui-cells weui-cells_after-title">
            <view class="weui-cell weui-cell_input">
              <input name="phonenumber" class="weui-input" placeholder="　请输入联系方式"/>
            </view>
          </view>
        </view>

        <view class="page-section">
          <view class="weui-cells__title">心愿需求<text class="red">　*</text></view>
          <view class="weui-cells__title_city">提交后，我们会尽快向您反馈</view>
          <view class="weui-cells weui-cells_after-title">
            <view class="weui-cell weui-cell_input">
              <textarea placeholder="　请输入心愿需求" class="weui-textarea" name="xinyuan_content"/>
              <!-- <input name="organizational_address" class="weui-input" placeholder="　请输入心愿需求"/> -->
            </view>
          </view>
        </view>

        <view class="btn-area">
          <button style="margin: 30rpx" type="primary" formType="submit">提交</button>          
        </view>
      </form>
    </view>

  </view>
</template>
<script>
import "./index.scss";
import request from "../../utils/request";
import {getToken} from '../../utils/token';
export default {
  data() {
    return {
    }
  },  
  methods: { 
    formSubmit(e) {
      var form_value = e.detail.value;
      var user_name = form_value.user_name;
      var phonenumber = form_value.phonenumber;
      var xinyuan_content = form_value.xinyuan_content;
      //let is_can_submit = true;
      if("" == user_name)
      {
        wx.showModal({
          title: '提示',
          content: "姓名不能为空",
          success (res) {            
          }
        })
        return;
      }

      if("" == phonenumber)
      {
        wx.showModal({
          title: '提示',
          content: "联系方式不能为空",
          success (res) {            
          }
        })
        return;
      }

      if("" == xinyuan_content)
      {
        wx.showModal({
          title: '提示',
          content: "心愿需求不能为空",
          success (res) {            
          }
        })
        return;
      }

      request('post', '/api/rest/tiny_wish.htm', {
        "openid": getToken(),
        "name": user_name,
        "phonenumber": phonenumber,
        "content": xinyuan_content
      }).then((res) => {
        var message = "提交成功";        
        if(200 != res.status_code)
          message = res.message;
        wx.showToast({
          title: message,
          icon: 'none',
          duration: 2000
        })     
      })
    }       
  },
};
</script>
